package service

import (
	"sdn-executor/core/snmp"
	model "sdn-executor/model/snmp"
)

func ExecuteSNMPGetCmd(query *model.Query) ([]*model.PDU, error) {

	client, err := snmp.NewSNMPClient(&query.BaseQuery)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	pdus, err := client.Get(query.OIDs)
	if err != nil {
		return nil, err
	}

	return pdus, nil
}

func ExecuteSNMPGetNextCmd(query *model.Query) ([]*model.PDU, error) {
	client, err := snmp.NewSNMPClient(&query.BaseQuery)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	pdus, err := client.GetNext(query.OIDs)
	if err != nil {
		return nil, err
	}

	return pdus, nil
}

func ExecuteSNMPGetBulkCmd(query *model.BulkQuery) ([]*model.PDU, error) {
	client, err := snmp.NewSNMPClient(&query.BaseQuery)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	pdus, err := client.GetBulk(query.OIDs, query.NonRepeaters, query.MaxRepetitions)
	if err != nil {
		return nil, err
	}

	return pdus, nil
}

func ExecuteSNMPBulkWalkCmd(query *model.WalkQuery) ([]*model.PDU, error) {
	client, err := snmp.NewSNMPClient(&query.BaseQuery)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	pdus, err := client.BulkWalk(query.OID)
	if err != nil {
		return nil, err
	}

	return pdus, nil
}

func ExecuteSNMPWalkCmd(query *model.WalkQuery) ([]*model.PDU, error) {
	client, err := snmp.NewSNMPClient(&query.BaseQuery)
	if err != nil {
		return nil, err
	}
	defer client.Close()

	pdus, err := client.Walk(query.OID)
	if err != nil {
		return nil, err
	}

	return pdus, nil
}
